package com.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.Hidden;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class PanelPaypal extends Composite {

	private Panel wrapper;
	private Button payer = new Button("Payer");
	FormPanel form = new FormPanel("");
	 
	public PanelPaypal() {
        wrapper = new VerticalPanel();
        initWidget(wrapper);
    }

    private FormPanel createPanel(final Object cart, String value) {        
        form.setAction("https://www.paypal.com/cgi-bin/webscr");
        form.setMethod(FormPanel.METHOD_POST);

        VerticalPanel panel = new VerticalPanel();
        form.setWidget(panel);

        panel.add(new Hidden("cmd","_xclick"));
        panel.add(new Hidden("business","spp_master@hotmail.com"));
        panel.add(new Hidden("upload","1"));
        panel.add(new Hidden("cancel_return","http://127.0.0.1:8888/Application.html?gwt.codesvr=127.0.0.1:9997"));
        panel.add(new Hidden("return","http://127.0.0.1:8888/Application.html?gwt.codesvr=127.0.0.1:9997"));

        panel.add(new Hidden("item_name", "Assurance"));
        panel.add(new Hidden("currency_code","EUR"));
        panel.add(new Hidden("amount", value));
        panel.add(new Hidden("quantity", String.valueOf(1)));

        
        panel.add(payer);
        return form;
    }
    
    private FormPanel createPanelDon(final Object cart) {
        final FormPanel form = new FormPanel("");
        form.setAction("https://www.paypal.com/cgi-bin/webscr");
        form.setMethod(FormPanel.METHOD_POST);

        VerticalPanel panel = new VerticalPanel();
        form.setWidget(panel);
        
        panel.add(new Hidden("cmd","_donations"));
        panel.add(new Hidden("business","spp_master@hotmail.com"));
        panel.add(new Hidden("upload","1"));
        panel.add(new Hidden("cancel_return","http://127.0.0.1:8888/Application.html?gwt.codesvr=127.0.0.1:9997"));
        panel.add(new Hidden("return","http://127.0.0.1:8888/Application.html?gwt.codesvr=127.0.0.1:9997"));

        panel.add(new Hidden("currency_code","EUR"));
       
        return form;
    }


    public void update(Object cart, String value) {
        //create your own Cart class to suit your app and call this update method to update the paypal panel
        wrapper.clear();
        wrapper.add(createPanel(cart, value));
    }
    
    public void updateDon(Object cart) {
        wrapper.clear();
        wrapper.add(createPanelDon(cart));
    }
    
    /**
	 * @return the payer
	 */
	public Button getButtonPayer() {
		return payer;
	}
	/**
	 * @return the form
	 */
	public FormPanel getForm() {
		return form;
	}
	
}
